<?php

include("global.php");

$pagetitle=" - Administration - Profile Fields";
$links=" > Administration > Profile Fields";

include ("header.php");

include ("admin_header.php");

if($userloggedinarray[15]!=="administrator"){
   unset($tplcontent);
   $tplcontent['notice']="Must be logged in as administrator to use control panel!";
   echo template('notice',$tplcontent);
}else{

if(!$addprofilefields&&!isset($editprofilefields)&&!isset($deleteprofilefields)&!$addprofilefields2&&!isset($editprofilefields2)){
unset($tplcontent);
	
 $profilefieldsarray=getdata("$configarray[5]/profilefields.php");
 
   for($n=0;$n<count($profilefieldsarray);$n++){

    $tplcontent['profilefields'].="<b>$profilefieldsarray[$n]</b>\n";
    $tplcontent['profilefields'].=" | <a href=\"admin_profilefields.php?editprofilefields=$n\">Edit</a>";
    $tplcontent['profilefields'].=" | <a href=\"admin_profilefields.php?deleteprofilefields=$n\">Delete</a>";

    $tplcontent['profilefields'].="<br><br>";

   }//end profilefields loop

   $tplcontent['addnew'].="<a href=\"admin_profilefields.php?addprofilefields=1\">Add new</a>";

   echo template('adminprofilefieldslist',$tplcontent);

 }

 if(isset($editprofilefields)){
 	unset($tplcontent);

 $profilefieldsarray=getdata("$configarray[5]/profilefields.php");

 $tplcontent['formheader'].="<form action=\"admin_profilefields.php\" method=post>";
 
 $tplcontent['formheader'].="<input type=hidden name=\"editprofilefields2\" value=\"$editprofilefields\" size=40>";

 $tplcontent['fieldid'].="Edit Profile Field $editprofilefields";

 $tplcontent['fieldname'].="<input type=text name=\"profilefieldname\" value=\"$profilefieldsarray[$editprofilefields]\" size=40 class=\"forminput\"><br><br>";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Update\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";
 
 echo template('adminprofilefieldedit',$tplcontent);

 }

 if(isset($editprofilefields2)){

 writedata("$configarray[5]/profilefields.php",$profilefieldname,$editprofilefields2);

   unset($tplcontent);
  $tplcontent['notice'].="Profile Field edited - <a href=\"admin_profilefields.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

 if($addprofilefields=="1"){


 $tplcontent['formheader'].="<form action=\"admin_profilefields.php\" method=post>";
 $tplcontent['formheader'].="<input type=hidden name=\"addprofilefields\" value=\"2\">";

 $tplcontent['fieldname'].="<input type=text name=\"profilefieldname\" size=40 class=\"forminput\"><br><br>";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Add\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";

 echo template('adminprofilefieldadd',$tplcontent);
 }

 if($addprofilefields=="2"){
 $profilefieldsarray=getdata("$configarray[5]/profilefields.php");
 $end=count($profilefieldsarray);

 writedata("$configarray[5]/profilefields.php",$profilefieldname,$end);

   unset($tplcontent);
   $tplcontent['notice']="Field added - <a href=\"admin_profilefields.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

 if(isset($deleteprofilefields)){
 deletedata("$configarray[5]/profilefields.php",$deleteprofilefields);

   unset($tplcontent);
   $tplcontent['notice'].="Profile Field $deleteprofilefields deleted - <a href=\"admin_profilefields.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

}
include("admin_footer.php");

include("footer.php");

?>